//
//  RecordEditMenuView.m
//  BDD_TWO
//
//  Created by XTW on 2023/6/9.
//

#import "RecordEditMenuView.h"
#import "RecordCutViewController.h"
#import "RecordSplitViewController.h"
#import "RecordSplicingViewController.h"
#import "RecordToneViewController.h"
#import "RecordVolumeViewController.h"
#import "RecordReverbViewController.h"
#import "RecordRateViewController.h"
#import "RecordChangeViewController.h"
#import "CustomAlertView.h"

@interface RecordEditMenuView()
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;

@end

@implementation RecordEditMenuView

- (instancetype)initCustomView:(CGRect)frame {
    self = [[[NSBundle mainBundle] loadNibNamed:@"RecordEditMenuView" owner:self options:nil] lastObject];
    if (self) {
        [self setFrame:frame];
        [self.scrollView setContentSize:CGSizeMake(444, 0)];
    }
    return self;
}

- (IBAction)clickPress:(UIButton *)sender {
    NSInteger type = sender.tag - 100;
    if ([self.dataSource respondsToSelector:@selector(dataSourceLocalRecord)]) {
        LocalRecordModel *model = [self.dataSource dataSourceLocalRecord];
        if (type == 0) {
            RecordCutViewController *viewCon = [[RecordCutViewController alloc] initWithNibName:@"RecordCutViewController" bundle:nil];
            viewCon.model = model;
            viewCon.ReloadHandle = ^(NSURL * _Nonnull url, NSString * _Nonnull fileName) {
                if ([self.delegate respondsToSelector:@selector(recordEditMenuViewCutReloadUrl:name:)]) {
                    [self.delegate recordEditMenuViewCutReloadUrl:url name:fileName];
                }
            };
            viewCon.DeleteHandle = ^(LocalRecordModel * _Nonnull dModel) {
                if ([self.delegate respondsToSelector:@selector(recordEditMenuViewDelete:)]) {
                    [self.delegate recordEditMenuViewDelete:dModel];
                }
                if ([self.dataSource dataSourceArray].count > 1) {
                    [[UIViewControllerCJHelper findCurrentShowingViewController].navigationController popViewControllerAnimated:YES];
                }
            };
            [[UIViewControllerCJHelper findCurrentShowingViewController].navigationController pushViewController:viewCon animated:YES];
        } else if (type == 1) {
            RecordSplitViewController *viewCon = [[RecordSplitViewController alloc] initWithNibName:@"RecordSplitViewController" bundle:nil];
            viewCon.model = model;
            viewCon.ReloadHandle = ^(NSArray * _Nonnull models) {
                if ([self.delegate respondsToSelector:@selector(recordEditMenuViewSplitReloadModels:)]) {
                    [self.delegate recordEditMenuViewSplitReloadModels:models];
                }
            };
            viewCon.DeleteHandle = ^(LocalRecordModel * _Nonnull dModel) {
                if ([self.delegate respondsToSelector:@selector(recordEditMenuViewDelete:)]) {
                    [self.delegate recordEditMenuViewDelete:dModel];
                }
            };
            [[UIViewControllerCJHelper findCurrentShowingViewController].navigationController pushViewController:viewCon animated:YES];
        } else if (type == 2) {
            RecordSplicingViewController *viewCon = [[RecordSplicingViewController alloc] initWithNibName:@"RecordSplicingViewController" bundle:nil];
            viewCon.contentArr = [self.dataSource dataSourceArray];
            viewCon.ReloadHandle = ^(NSArray * _Nonnull models) {
                if ([self.delegate respondsToSelector:@selector(recordEditMenuViewReloadModels:)]) {
                    [self.delegate recordEditMenuViewReloadModels:models];
                }
            };
            [[UIViewControllerCJHelper findCurrentShowingViewController].navigationController pushViewController:viewCon animated:YES];
        } else if (type == 3) {
            RecordToneViewController *viewCon = [[RecordToneViewController alloc] initWithNibName:@"RecordToneViewController" bundle:nil];
            viewCon.model = model;
            viewCon.ReloadHandle = ^(NSURL * _Nonnull url, NSString * _Nonnull fileName) {
                if ([self.delegate respondsToSelector:@selector(recordEditMenuViewCutReloadUrl:name:)]) {
                    [self.delegate recordEditMenuViewCutReloadUrl:url name:fileName];
                }
            };
            [[UIViewControllerCJHelper findCurrentShowingViewController].navigationController pushViewController:viewCon animated:YES];
        } else if (type == 4) {
            RecordVolumeViewController *viewCon = [[RecordVolumeViewController alloc] initWithNibName:@"RecordVolumeViewController" bundle:nil];
            viewCon.model = model;
            viewCon.ReloadHandle = ^(NSURL * _Nonnull url, NSString * _Nonnull fileName) {
                if ([self.delegate respondsToSelector:@selector(recordEditMenuViewCutReloadUrl:name:)]) {
                    [self.delegate recordEditMenuViewCutReloadUrl:url name:fileName];
                }
            };
            [[UIViewControllerCJHelper findCurrentShowingViewController].navigationController pushViewController:viewCon animated:YES];
        } else if (type == 5) {
            RecordReverbViewController *viewCon = [[RecordReverbViewController alloc] initWithNibName:@"RecordReverbViewController" bundle:nil];
            viewCon.model = model;
            viewCon.ReloadHandle = ^(NSURL * _Nonnull url, NSString * _Nonnull fileName) {
                if ([self.delegate respondsToSelector:@selector(recordEditMenuViewCutReloadUrl:name:)]) {
                    [self.delegate recordEditMenuViewCutReloadUrl:url name:fileName];
                }
            };
            [[UIViewControllerCJHelper findCurrentShowingViewController].navigationController pushViewController:viewCon animated:YES];
        } else if (type == 6) {
            RecordChangeViewController *viewCon = [[RecordChangeViewController alloc] initWithNibName:@"RecordChangeViewController" bundle:nil];
            viewCon.model = model;
            viewCon.ReloadHandle = ^(NSURL * _Nonnull url, NSString * _Nonnull fileName) {
                if ([self.delegate respondsToSelector:@selector(recordEditMenuViewCutReloadUrl:name:)]) {
                    [self.delegate recordEditMenuViewCutReloadUrl:url name:fileName];
                }
            };
            [[UIViewControllerCJHelper findCurrentShowingViewController].navigationController pushViewController:viewCon animated:YES];
        } else if (type == 7) {
            RecordRateViewController *viewCon = [[RecordRateViewController alloc] initWithNibName:@"RecordRateViewController" bundle:nil];
            viewCon.model = model;
            viewCon.ReloadHandle = ^(NSURL * _Nonnull url, NSString * _Nonnull fileName) {
                if ([self.delegate respondsToSelector:@selector(recordEditMenuViewCutReloadUrl:name:)]) {
                    [self.delegate recordEditMenuViewCutReloadUrl:url name:fileName];
                }
            };
            [[UIViewControllerCJHelper findCurrentShowingViewController].navigationController pushViewController:viewCon animated:YES];
        } else if (type == 8){
            CustomAlertView *alertView = [[CustomAlertView alloc] initItem:@"确定要删除该音频？" withButtons:[NSArray arrayWithObjects:@"取消", @"确定", nil]];
            alertView.SureHandle = ^{
                if ([self.delegate respondsToSelector:@selector(recordEditMenuViewDelete:)]) {
                    [self.delegate recordEditMenuViewDelete:model];
                }
            };
            [alertView backgroundClickDisable];
            [alertView show];
        }
        
    }
}
@end
